import { createRouter,createWebHashHistory, RouteRecordRaw } from "vue-router"
import { configure,start,done } from "nprogress"
import permissionRouter from "./modules/permission"
import remainingRouter from "./modules/remaining" // 静态路由

// import { store } from "/@/store"
// vite.config.ts中alias:setAlias 配置 import Home from "../views/Home.vue"; 
configure({ showSpinner: false })

// 静态路由页面
export const allowRouter:Array<RouteRecordRaw> = [
  {
    path:"/",
    name:"Home",
    meta:{
      title:"首页"
    },
    component:() => import("/@/views/demo/Home.vue")
  }
]

const router = createRouter({
  history:createWebHashHistory(),
  // 路由地址
  routes:allowRouter
})

router.beforeEach((to,from) => {
  start()
  // console.log(store.state.taskList,"路由router使用store中的值")
  const reg = new RegExp(/^(.+)(\s\|\s.+)$/)
  // 修改页面title 
  const appTitle = import.meta.env.VITE_APP_TITLE as any
  document.title = appTitle.match(reg) ? appTitle.replace(reg, `${to.meta.title}$2`) : `${to.meta.title} | ${appTitle}`
})

router.afterEach(() => {
  done()
})

export default router